Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compaction: remove all cache dirs at the end of each run #1587

Merged
merged 14 commits into from
Oct 10, 2019

Conversation

krasi-georgiev
Copy link
Contributor

@krasi-georgiev krasi-georgiev commented Sep 30, 2019

Signed-off-by: Krasi Georgiev 8903888+krasi-georgiev@users.noreply.github.com
fixes: #1499

TODO

  • tests

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
.
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions (:

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -221,11 +221,6 @@ func runCompact(
indexCacheDir = path.Join(dataDir, "index_cache")
)

if err := os.RemoveAll(downsamplingDir); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not remove it? I think we need that still. What if compactor crashes/is restarted not gracefully? Then deferred removal will fail and Thanos will use more disk then needed if not worse - might end up having corrupted blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not removed , it is just moved inside the .Compact() method. This makes it consitent with all the how the other components handle removing the tmp files.

Copy link
Contributor Author

@krasi-georgiev krasi-georgiev Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I just double checked and I removed it because it is redundant as the compactor removes these before every compaction in

thanos/pkg/compact/compact.go

Lines 1044 to 1047 in 3646e13

// Clean up the compaction temporary directory at the beginning of every compaction loop.
if err := os.RemoveAll(c.compactDir); err != nil {
return errors.Wrap(err, "clean up the compaction temporary directory")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but c.compactDir is different then downsamplingDir 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correction It is a duplicate of

if err := os.RemoveAll(dir); err != nil {
return errors.Wrap(err, "clean working directory")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but that would be cleaned only after (!) compaction, so long time. I am 99% sure we need to keep this.

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Copy link
Contributor Author

@krasi-georgiev krasi-georgiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now added tests which verify the correct behavior.

@@ -221,11 +221,6 @@ func runCompact(
indexCacheDir = path.Join(dataDir, "index_cache")
)

if err := os.RemoveAll(downsamplingDir); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not removed , it is just moved inside the .Compact() method. This makes it consitent with all the how the other components handle removing the tmp files.

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
@krasi-georgiev
Copy link
Contributor Author

ping @bwplotka

"github.com/thanos-io/thanos/pkg/testutil"
)

func TestCleanupCompactCacheFolder(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not having those inside package responsible for deleting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it will require duplicating the bootstrap function.
I thought to put the bootstrap in some reusable package, but don't think it is generic enough to be useful anywhere else.
If it happens that that func becomes useful in other tests would revisit and refactor.

@@ -221,11 +221,6 @@ func runCompact(
indexCacheDir = path.Join(dataDir, "index_cache")
)

if err := os.RemoveAll(downsamplingDir); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but c.compactDir is different then downsamplingDir 🤔

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
# Conflicts:
#	CHANGELOG.md

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
@bwplotka bwplotka merged commit a09a4b9 into thanos-io:master Oct 10, 2019
@krasi-georgiev krasi-georgiev deleted the cleanup-temp-files branch October 10, 2019 11:56
GiedriusS pushed a commit that referenced this pull request Oct 28, 2019
* remove all cache dirs at the end of each run

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* changelog

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* .

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* changelog formating and pr num.

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* added test for the compaction cleanup

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* added tests

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* check error

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* move GatherAndCompare to tesutil

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* comment

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* nit

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>

* Added back deletion of the downsampling dir.

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>

* Fix after pull master.

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compactor: Compaction of Raw Data without cleaning local Disk
2 participants